/*
项目:实现三个可旋转的小风扇
班级:大数据1902班
姓名:王泓鑫
学号:19408080213
 */
package Fan;

import javafx.animation.Animation;
import javafx.animation.KeyFrame;
import javafx.animation.Timeline;
import javafx.application.Application;
import javafx.event.EventHandler;
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.HBox;
import javafx.scene.layout.Pane;
import javafx.scene.paint.Color;
import javafx.scene.shape.Arc;
import javafx.scene.shape.ArcType;
import javafx.scene.shape.Circle;
import javafx.stage.Stage;
import javafx.util.Duration;
import javafx.event.ActionEvent;
//import java.awt.event.ActionEvent;
import javax.lang.model.element.ElementVisitor;
import java.util.EventListener;

public class Test extends Application {


    public static void main(String[] args) {
        launch(args);
    }
    @Override
    public void start(Stage primaryStage) {
        //创建三个圆
        FanAchieve fan = new FanAchieve();



        //水平存放按钮，间距为5
        HBox hbox = new HBox(10);
        Button btPause = new Button("一号风扇转速最慢Start");
        Button btResume = new Button("end1");
        //按钮靠右
        hbox.setAlignment(Pos.BOTTOM_LEFT);
        hbox.getChildren().addAll(btPause, btResume);

        HBox hbox1 = new HBox(10);
        Button btPause1 = new Button("二号风扇转速中等Start");
        Button btResume1 = new Button("end2");
        //按钮放中间
        hbox1.setAlignment(Pos.BOTTOM_CENTER);
        hbox1.getChildren().addAll(btPause1, btResume1);


        HBox hbox2 = new HBox(10);
        Button btPause2 = new Button("三号风扇转速最快Start");
        Button btResume2 = new Button("end3");
        //按钮放在右边
        hbox2.setAlignment(Pos.BOTTOM_RIGHT);
        hbox2.getChildren().addAll(btPause2, btResume2);

        HBox hbox3 = new HBox(10);
        Button btPause3 = new Button("start all");
        Button btResume3 = new Button("end all");
        //Button moreSpdde = new Button("speedUp");
        //总控制按钮放中间
        hbox3.setAlignment(Pos.BOTTOM_CENTER);
        hbox3.getChildren().addAll(btPause3,btResume3/*,moreSpdde*/);

        //三个圆放在最上方
        BorderPane pane = new BorderPane();
        pane.setTop(fan);
        //控制三个圆的按钮放在分别放在左中右
        pane.setLeft(hbox);
        pane.setCenter(hbox1);
        pane.setRight(hbox2);
        pane.setBottom(hbox3);

        //创建控制面板
        Scene scene = new Scene(pane, 1200, 600);
        primaryStage.setTitle("三个风扇");
        primaryStage.setScene(scene);
        primaryStage.show();

        //一开始风扇都处于静止状态
        //对于第一个风扇，创建一个KeyFrame用于每100ms运行一个动作事件move1
        Timeline animation = new Timeline(new KeyFrame(Duration.millis(90),e->fan.move1()));
        animation.setCycleCount(Timeline.INDEFINITE);

        //对于第一个风扇，创建一个KeyFrame用于每100ms运行一个动作事件move1
        Timeline animation1 = new Timeline(new KeyFrame(Duration.millis(60),e->fan.move2()));
        animation1.setCycleCount(Timeline.INDEFINITE);

        //对于第一个风扇，创建一个KeyFrame用于每100ms运行一个动作事件move1
        Timeline animation2 = new Timeline(new KeyFrame(Duration.millis(30),e->fan.move3()));
        animation2.setCycleCount(Timeline.INDEFINITE);



        //使用lambda表达式简化表达式
        //点击start按钮开始转动
        btPause.setOnAction(e->animation.play());
        //点击end按钮结束
        btResume.setOnAction(e->animation.pause());

        btPause1.setOnAction(e->animation1.play());
        btResume1.setOnAction(e->animation1.pause());

        btPause2.setOnAction(e->animation2.play());
        btResume2.setOnAction(e->animation2.pause());

        //点击start all按钮所有风扇开始
        btResume3.setOnAction(e-> {
            animation.pause();
            animation1.pause();
            animation2.pause();
        });
        //点击end all按钮所有风扇停止
        btPause3.setOnAction(e-> {
            animation.play();
            animation1.play();
            animation2.play();
        });

    }

}
